package com.luocj.brvah_srl.activity;

import android.support.design.widget.AppBarLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.luocj.brvah_srl.R;
import com.luocj.brvah_srl.adapter.NestedAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.List;

public class NestedScroActivity extends AppCompatActivity {

    private SmartRefreshLayout smartrefreshlayout;
    private RecyclerView recyclerview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nested_scro);
        initView();
    }

    private void initView() {
        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        smartrefreshlayout = findViewById(R.id.smartrefreshlayout);
        recyclerview = findViewById(R.id.recyclerview);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerview.setLayoutManager(linearLayoutManager);
        NestedAdapter nestedAdapter = new NestedAdapter(NestedScroActivity.this,R.layout.item_text,getString());
        recyclerview.setAdapter(nestedAdapter);
//        /**
//         * 监听 AppBarLayout 的关闭和开启 ActionButton 设置关闭隐藏动画
//         */
//        AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
//        appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
//            boolean misAppbarExpand = true;
//            View fab = findViewById(R.id.fab);
//            @Override
//            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
//                int scrollRange = appBarLayout.getTotalScrollRange();
//                float fraction = 1f * (scrollRange + verticalOffset) / scrollRange;
//                if (fraction < 0.1 && misAppbarExpand) {
//                    misAppbarExpand = false;
//                    fab.animate().scaleX(0).scaleY(0);
//                }
//                if (fraction > 0.8 && !misAppbarExpand) {
//                    misAppbarExpand = true;
//                    fab.animate().scaleX(1).scaleY(1);
//                }
//            }
//        });
    }

    private List<String> getString (){
        ArrayList<String> mDatas = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            mDatas.add("---->" + i);
        }
        return mDatas;
    }
}
